package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CustomerInfoMapper;
import com.ruoyi.system.domain.CustomerInfo;
import com.ruoyi.system.service.ICustomerInfoService;

/**
 * 客户信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-21
 */
@Service
public class CustomerInfoServiceImpl implements ICustomerInfoService 
{
    @Autowired
    private CustomerInfoMapper customerInfoMapper;

    /**
     * 查询客户信息
     * 
     * @param customerId 客户信息主键
     * @return 客户信息
     */
    @Override
    public CustomerInfo selectCustomerInfoByCustomerId(String customerId)
    {
        return customerInfoMapper.selectCustomerInfoByCustomerId(customerId);
    }

    /**
     * 查询客户信息列表
     * 
     * @param customerInfo 客户信息
     * @return 客户信息
     */
    @Override
    public List<CustomerInfo> selectCustomerInfoList(CustomerInfo customerInfo)
    {
        return customerInfoMapper.selectCustomerInfoList(customerInfo);
    }

    /**
     * 新增客户信息
     * 
     * @param customerInfo 客户信息
     * @return 结果
     */
    @Override
    public int insertCustomerInfo(CustomerInfo customerInfo)
    {
        UUID uuid = UUID.randomUUID();
        customerInfo.setCustomerId(String.valueOf(uuid));

        // 查询手机号是否已经存在
        CustomerInfo list = customerInfoMapper.selectCustomerInfoByPhone(customerInfo.getContactInfo());
        if(list!=null){
            return -1;   //-1表示手机号已经存在
        }
        return customerInfoMapper.insertCustomerInfo(customerInfo);
    }

    /**
     * 修改客户信息
     * 
     * @param customerInfo 客户信息
     * @return 结果
     */
    @Override
    public int updateCustomerInfo(CustomerInfo customerInfo)
    {
        return customerInfoMapper.updateCustomerInfo(customerInfo);
    }

    /**
     * 批量删除客户信息
     * 
     * @param customerIds 需要删除的客户信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerInfoByCustomerIds(String[] customerIds)
    {
        return customerInfoMapper.deleteCustomerInfoByCustomerIds(customerIds);
    }

    /**
     * 删除客户信息信息
     * 
     * @param customerId 客户信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerInfoByCustomerId(String customerId)
    {
        return customerInfoMapper.deleteCustomerInfoByCustomerId(customerId);
    }

    @Override
    public String selectCustomerIdByPhone(String phoneNum) {
        CustomerInfo customerInfo = customerInfoMapper.selectCustomerInfoByPhone(phoneNum);
        if(customerInfo==null){
            return "获取失败,此手机号不存在,请重新输入!";
        }else {
            return customerInfo.getCustomerId();
        }

    }
}
